package com.zlq.cn.controller.api;

import com.alibaba.fastjson.JSON;
import com.zlq.cn.api.ApiMessage;
import com.zlq.cn.api.ApiParam;
import com.zlq.cn.service.un.PushService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/api/push")
public class PushController {

    @Resource
    private PushService pushService;

    @RequestMapping("/pushAccount")
    public Object pushAccount(@RequestBody ApiParam apiParam,
                              @NotNull(message = "目标用户不能为空") Integer userId,
                              String title,
                              String body,
                              String extParam) {
        pushService.pushAccount(null, userId, title, body, StringUtils.isNotEmpty(extParam) ? JSON.parseObject(extParam) : null);
        return ApiMessage.resultApiMessage("推送成功");
    }
}
